# $Id: PKGBUILD 79594 2012-11-08 15:25:54Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Maintainer: Ondrej Jirman <megous@megous.com>

pkgname=mingw32-gcc-base
pkgver=4.7.2
_w32apiver=3.17
_runtimever=3.20
_uprel=1
_upw32rel=1
pkgrel=1
arch=(i686 x86_64)
pkgdesc="A C cross-compiler for building Windows executables on Linux"
depends=(mingw32-binutils)
makedepends=(p7zip mingw32-runtime mingw32-w32api)
conflicts=(mingw32-gcc)
options=(!strip)
license=(GPL LGPL)
url="http://sourceforge.net/projects/mingw/files/MinGW/Base/gcc/Version4/"
source=(gcc-$pkgver-${_uprel}-mingw32-src.tar.lzma::http://downloads.sourceforge.net/project/mingw/MinGW/Base/gcc/Version4/gcc-$pkgver-${_uprel}/gcc-$pkgver-${_uprel}-mingw32-src.tar.lzma
	    http://downloads.sourceforge.net/project/mingw/MinGW/Base/w32api/w32api-${_w32apiver}/w32api-${_w32apiver}-${_upw32rel}-mingw32-src.tar.lzma
        http://downloads.sourceforge.net/project/mingw/MinGW/Base/mingw-rt/mingwrt-${_runtimever}/mingwrt-${_runtimever}-mingw32-src.tar.gz
        gcc-1-mingw-float.patch)
md5sums=('bc2d1828dd6c53683600545ca6a901e1'
         '89e5800096aa334009f98e7c1743d825'
         '26c0886cc60729b94956cc6d81cd076c'
         '2407123c35c0aa92ee5ffc27decca9a7')

build()
{
  if [ $NOEXTRACT -ne 1 ]; then
  # prepare headers
  mkdir -p $srcdir/mingw/include/
  cp -r $srcdir/w32api-${_w32apiver}-${_upw32rel}-mingw32/include/* \
    $srcdir/mingwrt-${_runtimever}-mingw32/include/* \
    $srcdir/mingw/include/

  unset CFLAGS CXXFLAGS

#  tar xJf gcc-$pkgver-${_uprel}-mingw32-src.tar.xz
  cd $srcdir
  tar xjf gcc-$pkgver-${_uprel}-mingw32-src/gcc-$pkgver.tar.bz2

  patch -d $srcdir/gcc-$pkgver -Np1 < $srcdir/gcc-1-mingw-float.patch

  mkdir -p $srcdir/build
  cd $srcdir/build

  chmod ugo+x $srcdir/gcc-$pkgver/configure
  chmod ugo+x $srcdir/gcc-$pkgver/move-if-change

  $srcdir/gcc-$pkgver/configure \
    --target=i486-mingw32 \
    --host=$CHOST \
    --build=$CHOST \
    --prefix=/usr \
    --enable-languages=c \
    --enable-sjlj-exceptions \
    --enable-hash-synchronization \
    --disable-nls \
    --disable-shared \
    --disable-libssp \
    --disable-libgomp \
    --with-build-sysroot=$srcdir \
    --with-headers=$srcdir/include
  else
    cd $srcdir/build
  fi

  make
  make install DESTDIR=$pkgdir

  cd $pkgdir
  rm -rf usr/bin/i486-mingw32-{gcov,gccbug,gcc-*} \
    usr/{include,lib/libiberty.a} usr/i486-mingw32 \
    usr/share/{info,man} usr/i486-mingw32
  strip usr/bin/*
  strip usr/libexec/gcc/i486-mingw32/$pkgver/{cc1*,collect2}
  i486-mingw32-strip -g usr/lib/gcc/i486-mingw32/$pkgver/*.a
}
